package com.net.wanjian.networkhospitalmanager.activity.my;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.net.wanjian.networkhospitalmanager.R;
import com.net.wanjian.networkhospitalmanager.activity.base.BaseActivity;
import com.net.wanjian.networkhospitalmanager.bean.UserInfoReturn;
import com.net.wanjian.networkhospitalmanager.net.HttpUtil;
import com.net.wanjian.networkhospitalmanager.netstatus.NetUtils;
import com.net.wanjian.networkhospitalmanager.utils.PicassoUtil;
import com.net.wanjian.networkhospitalmanager.utils.SharedXmlUtil;
import com.net.wanjian.networkhospitalmanager.utils.URLDecoderUtil;

import java.io.Serializable;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Description:
 * Created by lidongcai on 17/5/2.
 * Email:  lidongcaiocc@163.com
 */
public class PersonalInfoActivity extends BaseActivity {

    public static final String USER_INFO_INTENT_KEY = "com.wanjian.personalinfoactivity.userinfo";

    @BindView(R.id.top_back_layout)
    LinearLayout topBackLayout;
    @BindView(R.id.top_title_tv)
    TextView topTitleTv;
    @BindView(R.id.personal_info_header_iv)
    ImageView personalInfoHeaderIv;
    @BindView(R.id.personal_info_name_tv)
    TextView personalInfoNameTv;
    @BindView(R.id.personal_info_number_tv)
    TextView personalInfoNumberTv;
    @BindView(R.id.personal_info_sex_tv)
    TextView personalInfoSexTv;
    @BindView(R.id.personal_info_mentor_tv)
    TextView personalInfoMentorTv;
    @BindView(R.id.personal_info_mentor_layout)
    RelativeLayout personalInfoMentorLayout;
    @BindView(R.id.personal_info_phone_tv)
    TextView personalInfoPhoneTv;
    @BindView(R.id.personal_info_email_tv)
    TextView personalInfoEmailTv;

    @Override
    protected void initData() {

        PicassoUtil.loadImage(this,
                HttpUtil.getImageUrl(SharedXmlUtil.getInstance().getHospitalId(), SharedXmlUtil.getInstance().getUserInfoId(), 2),
                R.mipmap.user, personalInfoHeaderIv);

        Bundle bundle = getIntent().getExtras();
        UserInfoReturn infoReturn = (UserInfoReturn) bundle.getSerializable(USER_INFO_INTENT_KEY);
        if (!" ".equals(infoReturn.getData())){
            setPersonInfoUI(infoReturn.getData().getUserInfo());
        }

        topBackLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                PersonalInfoActivity.this.finish();
            }
        });

    }

    private void setPersonInfoUI(UserInfoReturn.DataBean.UserInfoBean userInfo) {

        if (SharedXmlUtil.getInstance().getUserIdentity().equals("1")){
            personalInfoMentorLayout.setVisibility(View.GONE);
        }else {
            personalInfoMentorLayout.setVisibility(View.VISIBLE);
        }

        String sex = "";
        if (URLDecoderUtil.getDecoder(userInfo.getUserInfoGender()).equals("1")){
            sex = "男";
        }
        if (URLDecoderUtil.getDecoder(userInfo.getUserInfoGender()).equals("2")){
            sex = "女";
        }

        personalInfoNameTv.setText(URLDecoderUtil.getDecoder(userInfo.getUserInfoTrueName()));
        personalInfoNumberTv.setText(URLDecoderUtil.getDecoder(userInfo.getUserInfoCode()));
        personalInfoSexTv.setText(sex);
        personalInfoMentorTv.setText(URLDecoderUtil.getDecoder(userInfo.getMajorTeacher()));
        personalInfoPhoneTv.setText(URLDecoderUtil.getDecoder(userInfo.getUserInfoPhone()));
        personalInfoEmailTv.setText(URLDecoderUtil.getDecoder(userInfo.getUserInfoEmail()));

    }


    @Override
    protected int getLayoutId() {
        return R.layout.activity_personal_info;
    }

    @Override
    protected void onNetworkConnected(NetUtils.NetType type) {

    }

    @Override
    protected void onNetworkDisConnected() {

    }

}
